"""
Created on 2022-05-26
@author:
"""
import os
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

ENV = os.environ.get('ENV_PROFILE')
if ENV == 'dev':  # 开发模式
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://"
    connect_args = {
        "user": "root",
        "password": "root",
        "database": "fast_api_demo",
        "host": "127.0.0.1",
        "port": 3306,
    }
elif ENV == 'test':  # 测试模式
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://"
    connect_args = {
        "user": "root",
        "password": "root",
        "database": "fast_api_demo",
        "host": "127.0.0.1",
        "port": 3306,
    }
elif ENV == 'production':  # 生产模式
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://"
    connect_args = {
        "user": "root",
        "password": "root",
        "database": "fast_api_demo",
        "host": "127.0.0.1",
        "port": 3306,
    }
else:  # 默认值
    # SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:root@localhost/fast_api"
    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://"
    connect_args = {
        "user": "root",
        "password": "root",
        "database": "fast_api_demo",
        "host": "127.0.0.1",
        "port": 3306,
    }

engine = create_engine(SQLALCHEMY_DATABASE_URI, connect_args=connect_args)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base(engine)
